Jerry's Blogs

Thursday, November 29, 2007

On Bad Code Day

It's like a bad hair day, except at the end of a bad code day, you usually don't have much hair left.

I should have noticed all the glaring warning signs before I started. Sunny skies, fantastic Y-Combinator infosession, solid meals... It was too good to last. Starting from worst news, I felt the full brunt of Rails 'Black Magic' working against me. I read through all the code and docs regarding ActiveRecord validation Callbacks only to find that most methods have empty bodies (magic!). I wanted our user model to be tested, so I tried overriding validations when isguest is true. It sounded simple enough. On top of that there were many many things that looked like what I wanted to do in the examples of the docs. I first tried to override 'save' to return true if guest and call super otherwise. Well for starters, it took me hours to realize I was using 'super' wrong by doing super.save instead of just plain super. To make matters worse, after I fixed my syntax error, only half of what I wanted would work. Namely, just manipulating users did what I expected, but adding a guest user to a 'gathering' would invalidate both the 'user' and the 'gathering' and leave them both unsaved. I tried to override and test various things in the 'gathering' model, but that yielded nothing either.

At this point, I got so sick of testing by hand that I thought I'd do the right thing and fill in some unit tests. Right away that we had no tests and that our fixtures were out of date. This meant spending time just updating the fixtures before I could even _approach_ testing. Only after futzing the tests did I notice a glaring mistake. I noticed that even freshly loaded fixtures would not validate. Impossible! Sadly, it was true. The culprit turned out to be two illogical validations: validates_presence_of :password, :password_confirmation. These two attributes are virtual fields used by validates_confirmation_of :password, but there are _no_ columns in the actual table for these two fields. What's actually stored is hashed_password, so it makes sense to validates_presence_of :hashed_password.

You'd think I'd reach at happy ending after all these hours, but on a bad code day , you simply cannot win. :(

Labels: ,

Monday, November 26, 2007

On Continued Postgresql Frustration

It's been a mix of failures and successes on getting Postgresql working on my Macs. For my Intel iMac, I got it working through 'fink' and had no problems with the ruby driver. I wrote down my experiences for future reference.

On my iBook, things were not as buttery. I already had Postgresql 8.1 installed via ports, but none of the headers were available for compiling the ruby drivers. To get that working, I had to install Xcode 3.0. Apparently, that didn't draw enough blood because when I tried compiling the driver, it gave me all kinds of endian-ness issues. What made it finally work was installing the rb-postgres package from ports. This is far from a clean setup though. I'm using the Apple bundled ruby and rails stacks found in /usr/bin, but at the same time I'm using the ports installed gems for postgres.

Next time that I need a working Postgresql solution on a Mac, I'll probably use a mac-ified package

Labels: ,

On Regret

Given the choice of sleeping right away, and checking Craiglist *one* last time before shut-eye, always choose the latter. 'Cause if you don't, then you end up kicking yourself for not having seen this gorgeous gem a few days earlier.

Labels:

Sunday, November 25, 2007

On Wendy's Art Skills

Does that look like me?

Saturday, November 24, 2007

On Afternoon Trinkets

From Arthur and Jeremy: <div id="container">   <div id="floating-left"></div>   <div id="floating-right"></div>   <br style="clear: left;">    </div>

The problem with this now if left floating div is too long, then the container div will only stretch to the length of the shorter div on the right. This could break some background or other layout. It might look something like this: (it's not working properly yet... I'll have to do more research before I get this.)

I'm too long!
I'm too short!

But with the proper fix, it would look like:

I'm too long!
I'm too short!

  • pushd and popd for quick remembering what directory you were in.
  • attachment_fu for quick rails attachments. Also does thumbs.
  • multiple style classes can applied to an element in left to right order: <div class="style_first style_second">
  • In general, 'class' is for styles that are generalized and reused among multiple elements, whereas 'id' is for one time specialized elements

Labels:

Wednesday, November 21, 2007

On Delusional Dreams

Oh, but what a dream. Up for auction is an insane mother of a car, the BMW 2003 M3 CSL. It's a lightened version of the already awesome M3, or as Jeremy Clarkson puts it, "it's a BMW with bulimia". The interesting part of this auction is how absolutely impossible it is: Pick the lowest unique bid.

This seems worse than a regular raffle. In a normal raffle, at least you have 1 in 'n' chance to win, where 'n' is the number of people. But in this new game, there are many more hurdles in front of you.

First you have to choose the lowest number. This isn't too hard to visualize; Simply order all incoming bids and choose the first one. Easy-peasey.

Unfortunately, there's also the matter of uniqueness. This means that even if you had chosen the lowest number, you still won't likely get the car since lots of other people probably picked the same number. You could choose a number with more digits to be more random, but then you're putting yourself further and further away from the lowest number. Psychologically, it's a catch-22. Choose a low number to get the LOWEST number, but choose a HIGH enough one to be unique.

What a fun and diabolical concept :)

On Gnu Screen Movement

Finally got sick of scrolling line by line in screen, and did some reading in the man page. The defaults are Vi keybindings:

     Movement keys:
     h, j, k, l move the cursor line by line or column by column.
     0,  ^  and  $  move to the leftmost column, to the first or last non-
       whitespace character on the line.
     H, M and L move the cursor to the leftmost column of the top,  center
       or bottom line of the window.
     + and - positions one line up and down.
     G moves to the specified absolute line (default: end of buffer).
     | moves to the specified absolute column.
     w, b, e move the cursor word by word.
     B, E move the cursor WORD by WORD (as in vi).
     C-u  and  C-d  scroll  the display up/down by the specified amount of
       lines while preserving the cursor position. (Default: half  screen-
       full).
     C-b and C-f scroll the display up/down a full screen.
     g moves to the beginning of the buffer.
     % jumps to the specified percentage of the buffer.

Monday, November 19, 2007

On Using Rails Magic Outside of Ruby

I started out initially trying to just connect to Postgresql using the postgres driver. Unfortunately, this didn't work because my postgres was hanging. I was skeptical because different sites hosted different APIs for using the driver, but the official site gave the wrong ones (Oh! Java, how I miss thee).

This led to be reach into higher and more tested abstractions. I finally came across a hideously formatted wiki page that had many different peoples' attempts to use Rails black magic in normal Ruby. My favorite one, the one of least effort, was simply adding:

require File.dirname(__FILE__) + "/../config/environment"

or whatever the relative path the config/environment is. This will 'require' all the magical bits: models, active-record, rubygems, lib, and plugins. The other organizational bit I learned was to add a 'bin' directory at the top level for plain scripts that need be executed by cron.

Labels:

Monday, November 12, 2007

On Car Buying Frenzy

Bourban's black 1997 NA Miata took me by surprise, and I'm absolutely loving how it looks. There's several bumps and nicks, but it looks like it's in better shape than my other Craigslist prospects. Hopefully, I'm not making this an impulse buy...

wikipedia miata photo

Labels:

Monday, November 5, 2007

On Super Cool Mystery Site

Wendy sent me this, and I just love it: fancy flash site

Oracle is freaking rich, and I want a piece...